/**
 * Copyright(C)版权所有 中国电子科技集团公司第三十二研究所
 * @Title: VfileMenuController数据管理文件操作接口
 * @author: 肖小霞
 * @version: 1.0
 * @date: 2020/10/14
 * 备注:无
 */
package com.cetc32.dh.controller.rest;

import com.cetc32.dh.common.response.ResponseResult;
import com.cetc32.dh.entity.DataFile;
import com.cetc32.dh.service.DataFileService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Date;
import java.util.List;



/**
 * 数据管理文件类
 * @author: xiao
 * @version: 1.0
 * @date: 2020/10/14
 * 备注:无
 */
@Slf4j
@RestController
@RequestMapping("/rest/datamng/file")
public class DataFileController {

    @Autowired
    public DataFileService dataFileService;

    /**
     * 统计文件的个数
     * @return ResponseResult
     * 备注:2020.10.16 Deprecated By 徐文远
     */
    @Deprecated
    //@PostMapping(value = "/count")
    public ResponseResult count() {
        Integer count = dataFileService.count();
        return ResponseResult.success(count);
    }

    /**
     * 插入文件
     * @param dataFile
     * @return ResponseResult
     * 备注:无
     */
    @PostMapping(value = "/insert")
    public ResponseResult insert(DataFile dataFile) {
//        dataFile=new DataFile(16L,"DD16","CDV10","DSFD","SDFD",new Date(),"xx");
        Integer count = dataFileService.insertDataFile(dataFile);
        return ResponseResult.success(count);
    }

    /**
     * 更新文件
     * @param dataFile
     * @return ResponseResult
     * 备注:无
     */
    @PostMapping(value = "/update")
    public ResponseResult update(DataFile dataFile) {
//        dataFile=new DataFile(10L,"DD10","CDV10","DSFD10","SDFD10",null,"xx10");
        Integer count=dataFileService.updatebyId(dataFile);
        return ResponseResult.success(count);
    }

    /**
     * 根据文件id查找文件
     * @param id
     * @return ResponseResult
     * 备注:无
     */
    @PostMapping(value = "/select")
    public ResponseResult select(Long id) {

        DataFile dataFile = dataFileService.queryById(id);
        if(dataFile==null){
            return ResponseResult.error("没有id="+id+"的dataFile！");
        }
        return ResponseResult.success(dataFile);
    }

    /**
     * 根据文件id删除文件
     * @param id
     * @return ResponseResult
     * 备注:无
     */
    @PostMapping(value = "/deleteOne")
    public ResponseResult delete(Long id) {
        Integer count = dataFileService.deleteById(id);
        return ResponseResult.success(count);
    }

//    @RequestMapping(value = "/queryByStorageId")
//    public ResponseResult queryByStorageId(Long  fileStorageId) {
//        List<DataFile> dataFileList =dataFileService.queryByFileStorageId(fileStorageId);
//        return ResponseResult.success(dataFileList);
//    }

//    @RequestMapping(value = "/showMenusById")
//    public ResponseResult showMenusById(Long fileId) {
//        List<DataMenu> dataMenuList=dataFileService.showMenusByFileId(fileId);
//        return ResponseResult.success(dataMenuList);
//    }

    /**
     * 根据文件创建时间查询文件
     * @param time
     * @return ResponseResult
     * 备注:无
     */
    @PostMapping(value = "/selectAllByTime")
    public ResponseResult selectAllByTime(Date time) {
        List<DataFile> dataFileList=dataFileService.queryByTime(time);
        return ResponseResult.success(dataFileList);
    }

    /**
     * 根据文件区域查询文件
     * @param region
     * @return ResponseResult
     * 备注:无
     */
    @PostMapping(value = "/selectAllByRegion")
    public ResponseResult selectAllByRegion(String region) {
        List<DataFile> dataFileList=dataFileService.queryByRegion(region);
        return ResponseResult.success(dataFileList);
    }

    /**
     * 根据文件安全性查询文件
     * @param fileSecurity
     * @return ResponseResult
     * 备注:无
     */
    @PostMapping(value = "/selectAllByFileSecurity")
    public ResponseResult selectAllByFileSecurity(String fileSecurity) {
        List<DataFile> dataFileList=dataFileService.queryAllByFileSecurity(fileSecurity);
        return ResponseResult.success(dataFileList);
    }


}
